import json
import matplotlib.pyplot as plt

# 给定的字典数据
# data = {
#     0: [26, 0.6795060634613037, 0.30093932151794434, 0.45012974739074707],
#     1: [36, 31.12712574005127, 1.6235616207122803, 2.6818606853485107],
#     2: [19, 0.41179323196411133, 0.2844374179840088, 0.415302038192749],
#     3: [12, 210.8939859867096, 28.46364951133728, 94.54968214035034],
#     4: [18, 0.6398727893829346, 1.0236144065856934, 0.7110333442687988],
#     5: [6, 0.18059420585632324, 0.34037041664123535, 0.549013614654541],
#     6: [36, 21.45629572868347, 2.0800209045410156, 3.5085501670837402],
#     7: [39, 9.763112306594849, 2.412081480026245, 4.348714113235474],
#     8: [41, 23.608241081237793, 2.939275026321411, 27.87208914756775],
#     9: [23, 0.5410017967224121, 0.3731508255004883, 0.42504310607910156]
# }

# 从JSON文件中加载数据
with open('./data.json', 'r') as json_file:
    data = json.load(json_file)
# 按装箱个数进行排序
sorted_data = sorted(data.items(), key=lambda x: x[1][0])

# 提取排序后的数据
counts = [entry[1][0] for entry in sorted_data]
method1_times = [entry[1][1] for entry in sorted_data]
method2_times = [entry[1][2] for entry in sorted_data]
method3_times = [entry[1][3] for entry in sorted_data]

# 绘制折线图
plt.plot(counts, method1_times, label='Method 1')
plt.plot(counts, method2_times, label='Method 2')
plt.plot(counts, method3_times, label='Method 3')

# 添加标题和标签
plt.title('Boxing Time vs. Count for Different Methods')
plt.xlabel('Count')
plt.ylabel('Time (seconds)')

# 添加图例
plt.legend()

# 显示图形
plt.show()
